<template>
  <div>
    <h1>当前求和为:{{ sum }}</h1>
    <select v-model="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increase">+</button>
    <button @click="decrease">-</button>
    <button @click="increaseOdd">当前求和奇数再加</button>
    <button @click="increaseWait">等一等再加</button>
  </div>
</template>

<script>
export default {
  name: "Count",
  data() {
    return {
      n: 1,
      sum: 0 //求和数
    };
  },methods:{
    increase(){
      console.log('0000000')
      this.sum+=this.n;
    },
    decrease(){
      this.sum -= this.n;
    },
    increaseOdd(){
      if(this.sum%2){
        this.sum+=this.n;
      }
    },
    increaseWait(){
        setTimeout(() => {
          this.sum+=this.n;
        }, 500);
    },
  }
};
</script>
<style scoped>
button {
  margin-left: 10px;
}
</style>
